<%-- 
    Document   : Auditoria
    Created on : 7/10/2011, 04:33:05 PM
    Author     : Ces
--%>

<%@ page import="PaquetesJL.*" %>
<%@page import="java.sql.ResultSet" %>
<%@page import="java.sql.ResultSetMetaData" %>


<jsp:include page="header.jsp"/>
<jsp:include page="ValidaUsuarioPermiso.jsp?id=Auditoria.jsp"/>

    <div class="story_title">
        <h2>Auditoria</h2>
    </div>
    <div class="clear"></div>
    <div class="story_content">
        
        <%
            HttpSession objSesion = request.getSession(false); 
            String usuario = (String)objSesion.getAttribute("username");
            
            if (usuario!=null && usuario.length() > 0 && (String)objSesion.getAttribute("valido")!=null)
            {
        %>
        
        Selecciona la cantidad de entradas a ver:
        
        <form method="get" >
            <select name="reporte">
                <option value=1>10</option>
                <option value=2>50</option>
                <option value=3>100</option>
            </select>

            <input type="submit" name="verReporte"/>
        </form>
       
        <%
                
                int option = 10;
                
                if(request.getParameter("reporte")!=null)
                    option = Integer.parseInt(request.getParameter("reporte"));

                option = option*10;
                
                if(request.getParameter("verReporte") != null)
                {
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");

                    String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
                    String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
                    String userName = pageContext.getServletContext().getInitParameter("userName");
                    String PasswordP = pageContext.getServletContext().getInitParameter("password");
                    String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");

                    byte[] decodedBytes = ConexionBD.decode(PasswordP);
                    String decodedPassword = new String(decodedBytes).trim();

                    ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
                    Conexion.IniciarConexion();
                    
                    ResultSet r = Conexion.EjecutarConsulta("SELECT TOP "+option+" * FROM BITACORA");
                    
                    ResultSetMetaData rs = r.getMetaData();
                    
                    try {
                        
                        out.println("<br><table cellpadding=5 cellspacing=3 border=1>");
                        out.println("<tr>");
                        for(int i = 1; i<=rs.getColumnCount(); i++)
                        {
                            out.println("<td><b>"+rs.getColumnName(i)+"</b></td>");
                        }
                        out.println("</tr>");
                        
                        while(r.next())
                        {
                            out.println("<tr>");
                            
                            for(int i = 1; i<=rs.getColumnCount(); i++)
                            {
                                out.println("<td>"+r.getString(i)+"</td>");
                            }
                            
                            out.println("</tr>");
                        }
                        out.println("</table>");

                    } catch (NullPointerException e) { out.println(e.getMessage()); }

                    
                    Conexion.CerrarConexion();
                }
    
        
        
            } else {
                
                response.sendRedirect("Autentica.jsp");
            }
        %>
        
    </div>




<jsp:include page="footer.jsp"/>